/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "tex_coords_util.h"

void TexCoordsUtil::Create(int32_t width, int32_t height, PointRect rect, float *array)
{
    // x0
    array[0] = static_cast<float>(rect.x) / width;
    // y0
    array[1] = static_cast<float>(rect.y) / height;

    // x1
    array[2] = static_cast<float>(rect.x) / width;
    // y1
    array[3] = (static_cast<float>(rect.y) + rect.h) / height;

    // x2
    array[4] = (static_cast<float>(rect.x) + rect.w) / width;
    // y2
    array[5] = static_cast<float>(rect.y) / height;

    // x3
    array[6] = (static_cast<float>(rect.x) + rect.w) / width;
    // y3
    array[7] = (static_cast<float>(rect.y) + rect.h) / height;
}

void TexCoordsUtil::Rotate90(float *array)
{
    // 0->2 1->0 3->1 2->3
    auto tx = array[0];
    auto ty = array[1];

    // 1->0
    array[0] = array[2];
    array[1] = array[3];

    // 3->1
    array[2] = array[6];
    array[3] = array[7];

    // 2->3
    array[6] = array[4];
    array[7] = array[5];

    // 0->2
    array[4] = tx;
    array[5] = ty;
}